<template>
  <div class="app-container pages">
    <div class="main-search">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
             class="main-search">
      <el-form-item label="进件日期" prop="applyTimeScope">
        <el-select v-model="queryParams.applyTimeScope" placeholder="不限" clearable @change="applyTimeScopeChange">
          <el-option
            v-for="dict in dict.type.apply_time_scope"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime" v-if="queryParams.applyTimeScope == 99">
        <el-date-picker
          v-model="queryParams.startTime"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          type="date"
          :clearable="false"
          :editable="false"
          placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime" v-if="queryParams.applyTimeScope == 99">
        <el-date-picker
          v-model="queryParams.endTime"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          type="date"
          :clearable="false"
          :editable="false"
          placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="部门" prop="deptId">
        <treeselect v-model="queryParams.deptId" style="" :options="deptOptions" :show-count="true"
                    placeholder="请选择归属部门" @keyup.enter.native="handleQuery"/>
      </el-form-item>

      <el-form-item label="业务员" prop="busName">
        <el-input
          v-model="queryParams.busName"
          placeholder=""
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="客户姓名" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="费率" prop="feerate">
        <el-input
          v-model="queryParams.feerate"
          placeholder="请输入费率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="进度" prop="revieweStatus">
        <el-select v-model="queryParams.revieweStatus" placeholder="不限" clearable>
          <el-option
            v-for="dict in dict.type.reviewe_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="批款银行" prop="inBank">
        <el-select v-model="queryParams.inBank" placeholder="请选择批款银行" clearable>
          <el-option
            v-for="dict in this.channelList"
            :key="dict.id + ''"
            :label="dict.name"
            :value="dict.id + ''"
          />
        </el-select>
      </el-form-item>


      <el-form-item label="批款时间" prop="pkApplyTimeScope">
        <el-select v-model="queryParams.pkApplyTimeScope" placeholder="不限" clearable @change="pkApplyTimeScopeChange">
          <el-option
            v-for="dict in dict.type.apply_time_scope"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="开始时间" prop="pkStartTime" v-if="queryParams.pkApplyTimeScope == 99">
        <el-date-picker
          v-model="queryParams.pkStartTime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="date"
          :clearable="false"
          :editable="false"
          placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="pkEndTime" v-if="queryParams.pkApplyTimeScope == 99">
        <el-date-picker
          v-model="queryParams.pkEndTime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="date"
          :clearable="false"
          :editable="false"
          placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>


      <el-form-item label="收款账户" prop="payeeType">
        <el-select v-model="queryParams.payeeType" placeholder="不限" clearable>
          <el-option
            v-for="dict in dict.type.payee_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="收款日期" prop="skApplyTimeScope">
        <el-select v-model="queryParams.skApplyTimeScope" placeholder="不限" clearable @change="skApplyTimeScopeChange">
          <el-option
            v-for="dict in dict.type.apply_time_scope"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="收款开始时间" prop="skStartTime" v-if="queryParams.skApplyTimeScope == 99">
        <el-date-picker
          v-model="queryParams.skStartTime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="date"
          :clearable="false"
          :editable="false"
          placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="收款结束时间" prop="skEndTime" v-if="queryParams.skApplyTimeScope == 99">
        <el-date-picker
          v-model="queryParams.skEndTime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="date"
          :clearable="false"
          :editable="false"
          placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="收款银行" prop="bank">
        <el-select v-model="queryParams.bank" placeholder="请选择收款银行" clearable>
          <el-option
            v-for="dict in this.channelList"
            :key="dict.id + ''"
            :label="dict.name"
            :value="dict.id + ''"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="录入日期" prop="lrApplyTimeScope">
        <el-select v-model="queryParams.lrApplyTimeScope" placeholder="不限" clearable @change="lrApplyTimeScopeChange">
          <el-option
            v-for="dict in dict.type.apply_time_scope"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="录入开始时间" prop="lrStartTime" v-if="queryParams.lrApplyTimeScope == 99">
        <el-date-picker
          v-model="queryParams.lrStartTime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="date"
          :clearable="false"
          :editable="false"
          placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="录入结束时间" prop="lrEndTime" v-if="queryParams.lrApplyTimeScope == 99">
        <el-date-picker
          v-model="queryParams.lrEndTime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="date"
          :clearable="false"
          :editable="false"
          placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="单件类型" prop="singletype">
        <el-select v-model="queryParams.singletype" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.singletype"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="来源" prop="source">
        <el-select v-model="queryParams.source" placeholder="-不限-" clearable >
          <el-option
            v-for="dict in dict.type.source_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"

          @click="handleAdd"
          v-hasPermi="['customer:revieweInfo:add']"
        >新增
        </el-button>
    </el-form>
    </div>
    <!--  @row-click="handleShow"    -->
    <div class="main-body">
      <div class="main-table">
    <el-table v-loading="loading" :data="revieweInfoList" size="mini" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="进件日期" align="center" prop="inTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="部门" align="center" prop="deptName" width="100px"/>
      <el-table-column label="业务员" align="center" prop="busName" width="80px"/>
      <el-table-column label="客户姓名" align="center" prop="customerName" width="80px"/>
      <el-table-column label="费率" align="center" prop="feerate">
        <template slot-scope="scope">
          <span> {{ scope.row.feerate }} %</span>
        </template>
      </el-table-column>
      <el-table-column label="进件额（元）" align="center" prop="quotaApply" width="100px"/>
      <el-table-column label="进度" align="center" prop="revieweStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.reviewe_status" :value="scope.row.revieweStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="批款银行" align="center" prop="inBank" :formatter="inBankFormat"show-overflow-tooltip />
      <el-table-column label="批款额（元）" align="center" prop="approveQuota" width="100px"/>
      <el-table-column label="批准时间" align="center" prop="approveTime">
        <template slot-scope="scope">
          {{formatDate(scope.row.approveTime)}}
        </template>
      </el-table-column>
<!--      <el-table-column label="收款额（元）" align="center" prop="approveQuota"/>-->
<!--      <el-table-column label="收款账户" align="center" prop="payeeType">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.payee_type" :value="scope.row.payeeType"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="收款日期" align="center" prop="payeeTime">
        <template slot-scope="scope">
          {{formatDate(scope.row.payeeTime)}}
        </template>
      </el-table-column>
      <el-table-column label="渠道费（元）" align="center" prop="channelFee" width="100px"/>
      <el-table-column label="诚意金（元）" align="center" prop="sincerityFee" width="100px"/>
      <el-table-column label="净收入（元）" align="center" prop="revenue" width="100px"/>
<!--      <el-table-column label="收款银行" align="center" prop="bank" :formatter="bankFormat"/>-->
<!--      <el-table-column label="录入日期" align="center" prop="createTime"/>-->
      <el-table-column label="单件类型" align="center" prop="singletype">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.singletype" :value="scope.row.singletype"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="bz" width="300px" :show-overflow-tooltip="true">
<!--        <template slot-scope="scope">-->
<!--          <div class="messageCard" v-html="scope.row.bz">-->
<!--          </div>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="来源" align="center" prop="source" width="120px" :show-overflow-tooltip="true">
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.source_type" :value="scope.row.source"/>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="审批说明" align="center" prop="description" width="100px"/>
      <el-table-column label="撤回说明" align="center" prop="withdrawInfoVo" width="100px">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="220">
        <template slot-scope="scope">
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-edit"-->
          <!--            @click.stop="handleUpdate(scope.row, '')"-->
          <!--          >详细-->
          <!--          </el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.revieweStatus == 4"
            @click.stop="handleUpdate(scope.row, 'audit')"
            v-hasPermi="['customer:revieweInfo:audit']"
          >审批

          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.revieweStatus == 13"
            @click.stop="handleUpdate(scope.row, 'loan')"
            v-hasPermi="['customer:revieweInfo:loan']"
          >放款
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.stop="handleUpdate(scope.row, 'retuenMoney')"
            v-if="scope.row.revieweStatus == 13 || scope.row.revieweStatus == 9"
            v-hasPermi="['customer:revieweInfo:retuenMoney']"
          >收款
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.stop="handleUpdate(scope.row, 'update')"
            v-hasPermi="['customer:revieweInfo:edit']"
          >修改
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.stop="handleWithdraw(scope.row)"
            v-hasPermi="['customer:revieweInfo:withdraw']"
          >撤回
          </el-button>

        </template>
      </el-table-column>
    </el-table>
      </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </div>

    <!-- 添加或修改再审件对话框 -->
    <el-drawer :title="title" :visible.sync="open" size="60%" append-to-body>
      <div style="margin: 10px 15px 60px 15px">
      <el-form ref="form" v-if="open" :model="form"
               :rules="operationType == 'audit' ? rules : operationType == 'loan' ? loanRules : retuenMoneyRules"
               label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="客户姓名" prop="customerName">
              <el-input v-model="form.customerName" placeholder="请输入客户姓名" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="顾问" prop="userName">
              <el-input v-model="form.userName" placeholder="" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="部门" prop="deptId" label-width="80px">
              <el-select v-model="form.deptId" placeholder="请选择部门" disabled>
                <el-option
                  v-for="dict in allDeptList"
                  :key="dict.deptId"
                  :label="dict.deptName"
                  :value="dict.deptId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="合同号" prop="contractNum">
              <el-input v-model="form.contractNum" placeholder="请输入合同号"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="费率" prop="feerate">
              <el-input v-model="form.feerate" placeholder="请输入费率">
                <i slot="suffix" style="font-style: normal; margin-right: 10px"> %</i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单件类型" prop="singletype">
              <el-select v-model="form.singletype" placeholder="请选择">
                <el-option
                  v-for="dict in dict.type.singletype"
                  :key="Number(dict.value)"
                  :label="dict.label"
                  :value="Number(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="进件银行" prop="inBank">
              <el-select v-model="form.inBank" placeholder="请选择进件银行" clearable>
                <el-option
                  v-for="dict in this.channelList"
                  :key="dict.id + ''"
                  :label="dict.name"
                  :value="dict.id + ''"
                />
              </el-select>
              <!--              <el-input v-model="form.inBank" placeholder="请输入进件银行"/>-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="进件额度" prop="quotaApply">
              <el-input type="number" v-model="form.quotaApply" placeholder="">
                <i slot="suffix" style="font-style: normal; margin-right: 10px"> 元</i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="进件日期" prop="inTime">
              <el-date-picker clearable
                              v-model="form.inTime"
                              type="date"
                              format="yyyy-MM-dd"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择进件时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="收款账户" prop="payeeType">
              <el-select v-model="form.payeeType" placeholder="请选择收款账户" clearable>
                <el-option
                  v-for="dict in dict.type.payee_type"
                  :key="Number(dict.value)"
                  :label="dict.label"
                  :value="Number(dict.value)"
                />
              </el-select>
<!--              <el-input v-model="form.payee" placeholder="请输入收款账户"/>-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="收款日期" prop="payeeTime">
              <el-date-picker clearable
                              v-model="form.payeeTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择收款日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
<!--          <el-col :span="8">-->
<!--            <el-form-item label="收款银行" prop="bank">-->
<!--              <el-select v-model="form.bank" placeholder="请选择进件银行" clearable>-->
<!--                <el-option-->
<!--                  v-for="dict in this.channelList"-->
<!--                  :key="dict.id + ''"-->
<!--                  :label="dict.name"-->
<!--                  :value="dict.id + ''"-->
<!--                />-->
<!--              </el-select>-->
<!--              &lt;!&ndash;              <el-input v-model="form.bank" placeholder="请输入收款银行"/>&ndash;&gt;-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="8">
            <el-form-item label="渠道经理" prop="channelManage">
              <el-input v-model="form.channelManage" placeholder="请输入渠道经理"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="放款额度" prop="approveQuota">
              <el-input type="number" v-model="form.approveQuota" placeholder="请输入放款额度">
                <i slot="suffix" style="font-style: normal; margin-right: 10px"> 元</i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="放款时间" prop="approveTime">
              <el-date-picker clearable
                              v-model="form.approveTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择放款时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
<!--          <el-col :span="8">-->
<!--            <el-form-item label="收款日期" prop="payeeTime">-->
<!--              <el-date-picker clearable-->
<!--                              v-model="form.payeeTime"-->
<!--                              type="datetime"-->
<!--                              value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                              placeholder="请选择收款日期">-->
<!--              </el-date-picker>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="客户转账" prop="getQuota">
              <el-input-number v-model="form.getQuota" placeholder="请输入客户转账"
                        @change="revenueChange(form.getQuota, 'getQuota')">
                <i slot="suffix" style="font-style: normal; margin-right: 10px"> 元</i>
              </el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="诚意金" prop="sincerityFee">
              <el-input-number v-model="form.sincerityFee" type="number" placeholder="请输入诚意金"
                        @change="revenueChange(form.sincerityFee, 'sincerityFee')">
                <i slot="suffix" style="font-style: normal; margin-right: 10px"> 元</i>
              </el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="渠道费" prop="channelFee">
              <el-input-number v-model="form.channelFee" type="number" placeholder="请输入渠道费"
                        @change="revenueChange(form.channelFee, 'channelFee')">
                <i slot="suffix" style="font-style: normal; margin-right: 10px"> 元</i>
              </el-input-number>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="净创收" prop="revenue">
              <el-input-number v-model="form.revenue" type="number" placeholder="" disabled>
                <i slot="suffix" style="font-style: normal; margin-right: 10px"> 元</i>
              </el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="还款期限" prop="deadline">
              <el-input v-model="form.deadline" placeholder="请输入还款期限"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="还款日期" prop="paybacktime">
              <el-date-picker clearable
                              v-model="form.paybacktime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择还款日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="备注" prop="bz">
            <el-input v-model="form.bz" type="textarea" placeholder=""/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="审核说明" prop="description">
            <div>
              <span>{{ form.description }}</span>
            </div>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="撤回说明" prop="withdrawInfoVo">
            <div v-html="form.withdrawInfoVo">
            </div>
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="合同" prop="htList">
              <upload-file ref="siteUpload"
                           disabled
                           v-model="form.htList"
                           multiple
                           @input="uploadUpdate"

                           :fileSize="5120"
                           pathPrefix="siteManage"></upload-file>

            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="记录信息" prop="remark" width="400px">
              <!--          <el-timeline v-for="(item, index) in bzRecordList">-->
              <!--            <el-timeline-item :timestamp="item.createBy + '  -  '  + item.createTime" placement="top">-->
              <!--              <h4>{{ item.content }}</h4>-->
              <!--            </el-timeline-item>-->
              <!--          </el-timeline>-->
              <template slot-scope="scope">
                <div class="messageCard" v-html="form.remark">
                </div>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="审核" prop="lsrevieweStatus" v-if="this.operationType == 'audit'">
          <el-radio-group v-model="form.lsrevieweStatus">
            <el-radio
              v-for="dict in this.revieweStatus"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="说明" prop="description" v-if="this.operationType == 'audit'">
          <el-input v-model="form.description" type="textarea" placeholder=""/>
        </el-form-item>
        <el-form-item label="金额配置">
          <el-radio-group v-model="form.disType" @change="disTypeChange(form.disType)">
            <el-radio
              v-for="dict in disTypeList"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="合作单" v-if="true">
          <div class="serve-person">
            <div class="serve-person-form-item" v-for="(item, index) in form.cooperateList" :key="item.key">
              <div class="item-op-icon" v-show="form.cooperateList.length > 1"
                   @click="removeCooperate(index)">
                <img class="item-delete-icon" src="@/assets/project/icon-minus.png" alt="">
              </div>
              <div class="item-form-box dialog-form" :style="{ '--form-item-width': '50px' }">
                <el-form-item label="人员" :prop="`cooperateList.${index}.userId`" label-width="70px" :rules="{
                      required: true, message: '人员不能为空', trigger: 'blur'
                    }">
                  <el-select v-model="item.userId" placeholder="请选择">
                    <el-option v-for="dict in userList" :key="dict.userId" :label="dict.userName"
                               :value="dict.userId"
                               :disabled="form.cooperateList.some(i => i.userId == dict.userId)"></el-option>
                  </el-select>
                </el-form-item>
              </div>
              <div class="item-form-box dialog-form" :style="{ '--form-item-width': '50px' }" v-if="form.disType == '1'">
                <el-form-item label="比例" :prop="`cooperateList.${index}.ratio`" label-width="70px" :rules="{
                      required: true, message: '比例不能为空', trigger: 'blur'
                    }">
                  <el-input-number v-model="item.ratio" :min="0"
                                   :max="99999999" :controls="false" placeholder="请输入比例">
                  </el-input-number>
                  <span> %</span>
                </el-form-item>
              </div>
              <div class="item-form-box dialog-form" :style="{ '--form-item-width': '50px' }" v-if="form.disType == '2'">
                <el-form-item label="金额" :prop="`cooperateList.${index}.ratio`" label-width="50px" :rules="{
                      required: true, message: '金额不能为空', trigger: 'blur'
                    }">
                  <el-input-number v-model="item.ratio" :min="0"
                                   :max="99999999" :controls="false" placeholder="请输入金额">
                  </el-input-number>
                  <span> 元</span>
                </el-form-item>
              </div>
            </div>
            <div class="serve-person-form-item" @click="addCooperate">
              <div class="add-btn">
                <img class="add-btn-icon" src="@/assets/project/icon-add.png" alt="">
                <span class="add-icon-text">增加</span>
              </div>
            </div>
          </div>
        </el-form-item>

      </el-form>
      </div>
      <div class="pop-footer">
        <el-button type="primary" :loading="buttonLoading" @click="submitForm">确 定</el-button>
        <el-button plain type="primary" @click="cancel">取 消</el-button>
      </div>
    </el-drawer>


    <!-- 记录每次的流程并更新时间信息 -->
    <el-dialog title="撤回再审件" :visible.sync="withdrawOpen" width="500px" append-to-body>
      <el-form ref="withdrawObjectForm" :model="withdrawObject" label-width="80px">
        <el-form-item label="撤回原因" prop="withdrawRemark" :rules="{required: true, message: '原因不能为空', trigger: 'blur'}">
          <el-input type="textarea" v-model="withdrawObject.withdrawRemark" placeholder="请填写撤回原因"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="withdrawSubmit">确 定</el-button>
        <el-button @click="withdrawOpen = false">取 消</el-button>
      </div>
    </el-dialog>

    <reviewe-customer ref="revieweCustomer"></reviewe-customer>
  </div>
</template>

<script>
import {
  listRevieweInfo,
  getRevieweInfo,
  delRevieweInfo,
  addRevieweInfo,
  updateRevieweInfo, withdrawSave
} from "@/api/customer/revieweInfo";
import {deptTreeSelect} from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import RevieweCustomer from "@/views/components/RevieweCustomer.vue";
import uploadFile from "@/components/ImageUpload";
import {getDeptInfoList, getUserList} from "@/api/customerPool/customerPool";
import {channelList} from "@/api/channel/channelInfo";
import {getRecordList} from "@/api/customer/customer"

export default {
  name: "RevieweInfo",
  components: {
    uploadFile,
    Treeselect,
    RevieweCustomer
  },
  dicts: ['singletype', 'apply_time_scope', 'source_type', 'customer_status', 'payee_type', 'reviewe_status'],
  data() {
    return {
      disTypeList: [
        {
          "value": "1",
          "label": "比例"
        },
        {
          "value": "2",
          "label": "指定金额"
        }
      ],
      revieweStatus: [
        {label: "审核通过", value: "13"},
        {label: "拒绝", value: "12"}
      ],
      // 所有部门信息
      allDeptList: [],
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 再审件表格数据
      revieweInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 部门树选项
      deptOptions: [],

      channelList: [],

      // 记录信息
      bzRecordList: [],

      revenueInfo: {
        getQuota: 0,
        sincerityFee: 0,
        channelFee: 0
      },

      userList: [],

      // 撤回操作
      withdrawOpen: false,
      withdrawObject: {
        id: "",
        customerId: "",
        withdrawRemark: ''
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        customerId: undefined,
        customerName: undefined,
        userId: undefined,
        userName: undefined,
        deptId: undefined,
        contractNum: undefined,
        feerate: undefined,
        quotaApply: undefined,
        inBank: undefined,
        inTime: undefined,
        singletype: undefined,
        status: undefined,
        approveQuota: undefined,
        approveTime: undefined,
        getQuota: undefined,
        sincerityFee: undefined,
        channelFee: undefined,
        revenue: undefined,
        payee: undefined,
        payeeType: undefined,
        payeeTime: undefined,
        bank: undefined,
        percentage: undefined,
        confirm: undefined,
        confirmtime: undefined,
        paybacktime: undefined,
        channelManage: undefined,
        deadline: undefined,
        revieweStatus: undefined,
        timeType: undefined,  // 时间类型

        applyTimeScope: undefined, // 进件
        startTime: undefined, // 自定义开始时间
        endTime: undefined, // 自定义结束时间

        skApplyTimeScope: undefined, //收款
        skStartTime: undefined,
        skEndTime: undefined,

        pkApplyTimeScope: undefined, // 批款
        pkStartTime: undefined,
        pkEndTime: undefined,

        lrApplyTimeScope: undefined, // 录入
        lrStartTime: undefined,
        lrEndTime: undefined,

        busName: undefined // 业务员
        ,
      },
      operationType: '',
      // 表单参数
      form: {},
      // 表单校验
      loanRules: {
        customerName: [
          {required: true, message: "客户姓名不能为空", trigger: "blur"}
        ],
        busName: [
          {required: true, message: "顾问不能为空", trigger: "blur"}
        ],
        deptId: [
          {required: true, message: "部门ID不能为空", trigger: "blur"}
        ],
        feerate: [
          {required: true, message: "费率不能为空", trigger: "blur"}
        ],
        singletype: [
          {required: true, message: "单件类型不能为空", trigger: "change"}
        ],
        inBank: [
          {required: true, message: "进件银行不能为空", trigger: "blur"}
        ],
        quotaApply: [
          {required: true, message: "进件额度不能为空", trigger: "blur"}
        ],
        inTime: [
          {required: true, message: "进件日期不能为空", trigger: "blur"}
        ],
        // bank: [
        //   {required: true, message: "收款银行不能为空", trigger: "blur"}
        // ],
        percentage: [
          {required: true, message: "不能为空", trigger: "blur"}
        ],
        channelManage: [
          {required: true, message: "渠道经理不能为空", trigger: "blur"}
        ],
        revieweStatus: [
          {required: true, message: "审核状态不能为空", trigger: "blur"}
        ],
        approveQuota: [
          {required: true, message: "放款额度不能为空", trigger: "blur"}
        ],
        approveTime: [
          {required: true, message: "放款时间不能为空", trigger: "blur"}
        ],
      },
      retuenMoneyRules: {
        customerName: [
          {required: true, message: "客户姓名不能为空", trigger: "blur"}
        ],
        busName: [
          {required: true, message: "顾问不能为空", trigger: "blur"}
        ],
        deptId: [
          {required: true, message: "部门ID不能为空", trigger: "blur"}
        ],
        feerate: [
          {required: true, message: "费率不能为空", trigger: "blur"}
        ],
        singletype: [
          {required: true, message: "单件类型不能为空", trigger: "change"}
        ],
        inBank: [
          {required: true, message: "进件银行不能为空", trigger: "blur"}
        ],
        quotaApply: [
          {required: true, message: "进件额度不能为空", trigger: "blur"}
        ],
        inTime: [
          {required: true, message: "进件日期不能为空", trigger: "blur"}
        ],
        // bank: [
        //   {required: true, message: "收款银行不能为空", trigger: "blur"}
        // ],
        percentage: [
          {required: true, message: "不能为空", trigger: "blur"}
        ],
        channelManage: [
          {required: true, message: "渠道经理不能为空", trigger: "blur"}
        ],
        revieweStatus: [
          {required: true, message: "审核状态不能为空", trigger: "blur"}
        ],
        approveQuota: [
          {required: true, message: "放款额度不能为空", trigger: "blur"}
        ],
        approveTime: [
          {required: true, message: "放款时间不能为空", trigger: "blur"}
        ],
        payeeTime: [
          {required: true, message: "收款时间不能为空", trigger: "blur"}
        ],
        getQuota: [
          {required: true, message: "客户转账 (尾款)不能为空", trigger: "blur"}
        ],
        sincerityFee: [
          {required: true, message: "诚意金不能为空", trigger: "blur"}
        ],
        channelFee: [
          {required: true, message: "渠道费不能为空", trigger: "blur"}
        ],
        revenue: [
          {required: true, message: "净创收    = 客户转账+诚意金- 渠道费不能为空", trigger: "blur"}
        ],
      },
      rules: {
        customerName: [
          {required: true, message: "客户姓名不能为空", trigger: "blur"}
        ],
        busName: [
          {required: true, message: "顾问不能为空", trigger: "blur"}
        ],
        deptId: [
          {required: true, message: "部门ID不能为空", trigger: "blur"}
        ],
        feerate: [
          {required: true, message: "费率不能为空", trigger: "blur"}
        ],
        singletype: [
          {required: true, message: "单件类型不能为空", trigger: "change"}
        ],
        inBank: [
          {required: true, message: "进件银行不能为空", trigger: "blur"}
        ],
        quotaApply: [
          {required: true, message: "进件额度不能为空", trigger: "blur"}
        ],
        inTime: [
          {required: true, message: "进件日期不能为空", trigger: "blur"}
        ],
        // bank: [
        //   {required: true, message: "收款银行不能为空", trigger: "blur"}
        // ],
        percentage: [
          {required: true, message: "不能为空", trigger: "blur"}
        ],
        channelManage: [
          {required: true, message: "渠道经理不能为空", trigger: "blur"}
        ],
        revieweStatus: [
          {required: true, message: "审核状态不能为空", trigger: "blur"}
        ],
        lsrevieweStatus: [
          {required: true, message: "审核状态不能为空", trigger: "blur"}
        ],
        description: [
          {required: true, message: "说明不能为空", trigger: "blur"}
        ]
      },
    };
  },
  created() {
    this.getList();
    this.channelListInit();
    this.getDeptTree();
    this.initDept();
    this.getUserInfoList();
  },
  methods: {

    formatDate(value) {
      if(value){
        const date = new Date(value);
        return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
      }
    },

    // 合作单类型 调整
    disTypeChange(newValue) {
      console.log("进来了：" + newValue);
      this.form.cooperateList.forEach(it => {
        it.ratio = '';
      })
    },

    /** 获取用户信息 */
    getUserInfoList() {
      const query = {
        type: "1"
      }
      getUserList(query).then(response => {
        this.userList = response.data;
      })
    },

    // 新增服务对象
    addCooperate() {
      this.form.cooperateList.push({
        id: undefined,
        deptId: undefined,
        userId: undefined,
        ratio: undefined,
        key: Date.now()
      })
    },

    // 移除信息
    removeCooperate(index) {
      this.form.cooperateList.splice(index, 1);
    },

    channelListInit() {
      channelList().then(resp => {
        this.channelList = resp.data;
      })
    },

    bankFormat(row, column) {
      const obj = this.channelList.find(it => it.id == row.bank);
      if (obj) {
        return obj.name;
      }
      return "";
    },

    inBankFormat(row, column) {
      const obj = this.channelList.find(it => it.id == row.inBank);
      if (obj) {
        return obj.name;
      }
      return "";
    },

    uploadUpdate() {
      this.$refs['form'].validateField('htList') // 此行单独校验form表单下的图片表单项
    },

    initDept() {
      getDeptInfoList().then(response => {
        this.allDeptList = response.data;
      });
    },

    /**  日期时间触发改变 */
    applyTimeScopeChange(val) {
      if (val != 99) {
        this.queryParams.startTime = undefined;
        this.queryParams.endTime = undefined;
      }
    },

    /**  收款日期时间触发改变 */
    skApplyTimeScopeChange(val) {
      if (val != 99) {
        this.queryParams.skStartTime = undefined;
        this.queryParams.skSendTime = undefined;
      }
    },

    /**  批款日期时间触发改变 */
    pkApplyTimeScopeChange(val) {
      if (val != 99) {
        this.queryParams.pkStartTime = undefined;
        this.queryParams.pkEndTime = undefined;
      }
    },

    /**  录入日期时间触发改变 */
    lrApplyTimeScopeChange(val) {
      if (val != 99) {
        this.queryParams.lrStartTime = undefined;
        this.queryParams.lrSendTime = undefined;
      }
    },

    revenueChange(val, type) {
      this.form.revenue =  this.form.sincerityFee + this.form.getQuota - this.form.channelFee;
      // if (type == 'channelFee') {
      //   this.revenueInfo.channelFee = val;
      // }
      // if (type == 'sincerityFee') {
      //   this.revenueInfo.sincerityFee = val;
      // }
      // if (type == 'getQuota') {
      //   this.revenueInfo.getQuota = val;
      // }
      // //this.form.revenue = Number(this.revenueInfo.sincerityFee) + Number(this.revenueInfo.getQuota) - Number(this.revenueInfo.channelFee);
      // this.form.revenue = this.revenueInfo.sincerityFee + this.revenueInfo.getQuota - this.revenueInfo.channelFee;
    },

    /** 获取右侧跟进记录 */
    recordList(id) {
      // 获取右侧备注信息
      getRecordList(id).then(response => {
        this.bzRecordList = response.data;
      })
    },

    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 查询再审件列表 */
    getList() {
      this.loading = true;
      listRevieweInfo(this.queryParams).then(response => {
        this.revieweInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        customerId: undefined,
        customerName: undefined,
        userId: undefined,
        userName: undefined,
        deptId: undefined,
        contractNum: undefined,
        feerate: undefined,
        quotaApply: undefined,
        inBank: undefined,
        inTime: undefined,
        singletype: undefined,
        status: undefined,
        approveQuota: undefined,
        approveTime: undefined,
        getQuota: undefined,
        sincerityFee: undefined,
        channelFee: undefined,
        revenue: undefined,
        payee: undefined,
        payeeType: undefined,
        payeeTime: undefined,
        bank: undefined,
        percentage: undefined,
        confirm: undefined,
        confirmtime: undefined,
        paybacktime: undefined,
        channelManage: undefined,
        deadline: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        revieweStatus: undefined,
        lsrevieweStatus: undefined,

        applyTimeScope: undefined, // 进件
        startTime: undefined, // 自定义开始时间
        endTime: undefined, // 自定义结束时间

        skApplyTimeScope: undefined, //收款
        skStartTime: undefined,
        skEndTime: undefined,

        pkApplyTimeScope: undefined, // 批款
        pkStartTime: undefined,
        pkEndTime: undefined,

        lrApplyTimeScope: undefined, // 录入
        lrStartTime: undefined,
        lrEndTime: undefined,

        busName: undefined,  // 业务员
        description: undefined,

        disType: "1",
        // 合作单
        cooperateList: []
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      //this.reset();
      //this.open = true;
      //this.title = "添加再审件";
      this.$refs.revieweCustomer.openDialog("");
    },
    handleShow(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getRevieweInfo(id).then(response => {
        this.loading = false;
        this.form = response.data;
        // this.operationType = this.form.revieweStatus
        this.open = true;
        this.title = "签约进件详情";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row, type) {
      //this.loading = true;
      this.reset();
      const id = row.id || this.ids
      this.operationType = type
      getRevieweInfo(id).then(response => {
       // this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改再审件";

        // 给属性赋值
        //this.revenueInfo = {
        //  getQuota: this.form.getQuota,
        //  sincerityFee: this.form.sincerityFee,
        //  channelFee: this.form.channelFee
        //}
        // 查询记录
        //this.recordList(response.data.customerId);
      });
    },
    /** 撤回操作---到待审核  */
    handleWithdraw(row) {
      this.withdrawObject = {
        id: row.id,
        customerId: row.customerId,
        withdrawRemark: ''
      }
      this.withdrawOpen = true;
    },
    withdrawSubmit() {
      this.$refs["withdrawObjectForm"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          console.log(8888, this.withdrawObject);
          withdrawSave(this.withdrawObject).then(res =>{
            this.$modal.msgSuccess("撤回成功");
            this.withdrawOpen = false;
            this.getList();
          }).finally(() => {
            this.buttonLoading = false;
          });
        }
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            this.form.operationType = this.operationType;
            if (this.operationType == 'audit') {
              this.form.revieweStatus = this.form.lsrevieweStatus;
            }
            // 处理部门信息
            this.form.cooperateList.forEach(it => {
              it.deptId = this.userList.find(item => item.userId == it.userId)?.deptId
            })
            updateRevieweInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
              this.form = {}
            });
          } else {
            addRevieweInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
              this.form = {}
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除再审件编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delRevieweInfo(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('customer/revieweInfo/export', {
        ...this.queryParams
      }, `revieweInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>

.messageCard {
  overflow-x: hidden;
  overflow-y: scroll;
  word-break: break-all;
  width: 400px;
  max-height: 100px;
  text-align: left;
  float: left;
  text-align: left;
  text-overflow: ellipsis;
  color: #313131;
}

.messageCard::-webkit-scrollbar {
  width: 4px;
}

.messageCard::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
}

.messageCard::-webkit-scrollbar-track {
  border-radius: 0;
  background: rgba(0, 0, 0, 0.1);
}


.serve-person {
  .serve-person-form-item {
    position: relative;
    padding-left: 32px;
    border-left: 1px solid #E3E6E5;
    display: flex;

    &::before {
      content: "";
      width: 20px;
      height: 1px;
      background: #E3E6E5;
      position: absolute;
      left: 0;
      top: 16px;
    }

    &:last-child {
      border: none;

      &::after {
        content: "";
        width: 550px;
        height: 16px;
        border-left: 1px solid #E3E6E5;
        position: absolute;
        left: 0;
        top: 0;
      }
    }

    .item-op-icon {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 20px;
      height: 32px;
      cursor: pointer;

      .item-delete-icon {
        width: 16px;
        height: 16px;
      }
    }
  }

  .add-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 80px;
    height: 32px;
    border-radius: 4px;
    border: 1px solid #E3E6E5;
    cursor: pointer;
    user-select: none;

    .add-btn-icon {
      width: 16px;
      height: 16px;
    }

    .add-btn-text {
      margin-left: 4px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #666666;
    }
  }
}
</style>
<style lang="css">
.el-tooltip__popper{
  max-width: 40%;
}
.tooltip-width{
  max-width: 40% !important;
}
.vue-treeselect__control {
  width: auto;
}

.vue-treeselect__value-container,
.vue-treeselect__multi-value {
  width: auto;
  vertical-align: middle;
}
</style>

<style lang="css">
.tooltip-width{
  max-width: 40% !important;
}
.vue-treeselect__control {
  width: auto;
}

.vue-treeselect__value-container,
.vue-treeselect__multi-value {
  width: auto;
  vertical-align: middle;
}
</style>
